home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / pascal / swag / comm.swg / 0034_Access PCBOARD Users.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-11-02  |  5.7 KB  |  195 lines

  1. {
  2. HELGE HELGESEN
  3.  
  4. -> Currently I am writing the USERS File to a  Temp File While im
  5. -> reading it (or atleast I try to), but pascal  does not allow
  6. -> me to Write a full Record to a File.
  7.  
  8. I suppose you're running a on a network, and that you have
  9. problems accessing the USERS File directly?
  10.  
  11. First of all, do you open the File in shared mode, which is
  12. necessary if multiple Programs to access the File simultaneous.
  13.  
  14. -> So could you  tell me an easier way Write back the
  15. -> modifications that I have  done. A little example would be
  16. -> Really cool..
  17.  
  18. Sure... Here's a little example. Tested With PCBoard configured
  19. for use on network, With DESQview.
  20.  
  21. if you'd relly try this you should reWrite the proc "ModifyRecord" first ;)
  22. }
  23.  
  24. Program AccessUsersFile;
  25.  
  26. Uses
  27.   Dos;
  28.  
  29. Type
  30.   bdReal = Array [0..7] of Byte; { I'm not sure of this one... }
  31.   bsReal = Array [0..3] of Byte; { have conversion routines For this one if you need }
  32.  
  33.   TUser = Record { declare user Record }
  34.     Name              : Array[ 1..25] of Char;
  35.     City              : Array [1..24] of Char;
  36.     PassWord          : Array [1..12] of Char;
  37.     Phone             : Array [1..2] of Array [1..13] of Char;
  38.     LastDateOn        : Array [1..6] of Char;
  39.     LastTimeOn        : Array [1..5] of Char;
  40.     Expert            : Char;
  41.     Protocol          : Char;
  42.     SomeBitFlags      : Byte;
  43.     DateOfLastDirScan : Array [1..6] of Char;
  44.     Level             : Byte;
  45.     TimesOn           : Word;
  46.     PageLen           : Byte;
  47.     FilesUploaded,
  48.     FilesDownloaded   : Word;
  49.     DownloadToday     : bdReal;
  50.     Comment           : Array [1..2] of Array [1..30] of Char;
  51.     ElapsedOn         : Word;
  52.     RegExpDate        : Array [1..6] of Char;
  53.     ExpLevel          : Byte;
  54.     OldLastConfIn     : Byte;
  55.     ConfRegBitFlags,
  56.     ExpRegBitFlags,
  57.     UserSelBitFlags   : Array [0..4] of Byte;
  58.     TotBytesDown,
  59.     TotBytesUp        : bdReal;
  60.     DeleteFlag        : Char;
  61.     LRP               : Array [0..39] of bsReal; { last read Pointers }
  62.     RecNoInUsersInf   : LongInt;
  63.     MoreBitFlags      : Byte;
  64.     RFU               : Array [1..8] of Char;
  65.     LastConfIn        : Word;
  66.   end;
  67.  
  68.   TIndex = Record { PCBNDX Files }
  69.     RecNo : Word;
  70.     Name  : Array [1..25] of Char;
  71.   end;
  72.  
  73. Var
  74.   UsersFile     : File of TUser;
  75.   PathToIndexes : String; { path to index Files, With 'PCBNDX.' added }
  76.   Users         : TUser; { global Record - users Record }
  77.  
  78. Procedure OpenUsersFile;
  79. Var
  80.   t : Text;
  81.   s : String;
  82.   x : Byte;
  83. begin
  84.   s := GetEnv('PCBDAT');
  85.   if length(s) = 0 then
  86.     halt; { if I can't find PCBOARD.DAT I can't find USERS File either }
  87.   assign(t, s); {$I+}
  88.   reset(t); { open File, will terminate if any error }
  89.   For x := 1 to 28 do
  90.     readln(t, s);
  91.   PathToIndexes := s + 'PCBNDX.';
  92.   FileMode := 66;
  93.   readln(t, s);
  94.   assign(UsersFile, s);
  95.   reset(UsersFile);
  96.   close(t);
  97. end;
  98.  
  99. Function FindUserRec: Word;
  100. { Searches thru index File For name. if not found, $FFFF is returned. }
  101. Var
  102.   name      : String;
  103.   IndexFile : File of TIndex;
  104.   x         : Byte;
  105.   Found     : Boolean;
  106.   Index     : TIndex;
  107. begin
  108.   Write('Enter name of user to modify: ');
  109.   readln(name);
  110.   FindUserRec := $ffff;
  111.   x := length(name);
  112.   name[0] := #25; { make 25 Char name }
  113.   For x := x + 1 to 25 do
  114.     name[x] := #32;
  115.   For x := 1 to 25 do
  116.     name[x] := UpCase(name[x]); { make upper Case }
  117. { since PCBoard v15.0 supports national Chars, you should do it too. If
  118.   you need, I have something on this too... ;) }
  119.   assign(IndexFile, PathToIndexes + name[1]);
  120.   reset(IndexFile);
  121.   Repeat
  122.     read(IndexFile, Index); { read name }
  123.     x := 1;
  124.     While (x <= 25) and (name[x] = Index.Name[x]) do
  125.       inc(x);
  126.     Found := x = 26;
  127.   Until eof(IndexFile) or Found;
  128.   if Found then
  129.     FindUserRec := Index.RecNo - 1;
  130. { Please note that I subtract 1 here. This is becase PCBoard was written in
  131.   Basic (when the File format was made) and that Basic threats Record 1 as
  132.   the first Record. In Pascal, Record 0 is the first Record! This may confuse
  133.   a bit since some Files Within PCBoard are 1-based, and some are 0-based. }
  134.   close(IndexFile);
  135. end;
  136.  
  137. Procedure ModifyRecord;
  138. { Let's modify the Record... }
  139. Var
  140.   x : Byte;
  141. begin
  142.   Write('Users name: ');
  143.   For x := 1 to 25 do
  144.     Write(Users.Name[x]);
  145.   Writeln; { For verification only... }
  146.   Users.Protocol:='Z'; { let's make him use Zmodem }
  147.   inc(Users.PassWord[1]); { and give him some headache }
  148.   Users.PageLen := 0; { and make the screen go non-stop, when he gets on again... }
  149. end;
  150.  
  151. Var
  152.   x : Word;
  153. begin
  154.   OpenUsersFile;
  155.   x := FindUserRec;
  156.   if x = $ffff then
  157.   begin
  158.     Writeln('Can''t locate user, sorry...');
  159.     close(UsersFile);
  160.     halt; { can't find user... }
  161.   end;
  162.   seek(UsersFile, x); { seek to the Record }
  163.   read(UsersFile, Users); { and read the Record }
  164.   seek(UsersFile, x); { seek back to the Record }
  165.   ModifyRecord; { make some modificatios... }
  166.   Write(UsersFile, Users); Writeln('Modifiations written back...');
  167.   close(UsersFile);
  168. end.
  169.  
  170.  
  171.  
  172. Var
  173.   Cnames  : File;
  174.   PCBConf : PCBConfType; { your declaration }
  175.  
  176. begin
  177.   { And now we need to open it }
  178.   assign(Cnames, 'CNAMES.@@@'); { I assume is't local }
  179.   FileMode := 66; { open in shared mode }
  180.   reset(Cnames, 1); { NB! Make RecSize = 1! }
  181.  
  182.   { Now, let's read the Record length. I assume X is an Word! }
  183.   blockread(Cnames, x, sizeof(x));
  184.  
  185.   { And now it's time to seek to conference Y(also a Word). }
  186.   seek(Cnames, 2 + y * x);
  187.  
  188.   { And read the Record. }
  189.   blockread(Cnames, PCBConf, sizeof(PCBConf));
  190.  
  191.   { There. if you want to Write back some modifications, }
  192.   seek(Cnames, 2 + x * y); { seek back to Record }
  193.   blockWrite(Cnames, PCBConf, sizeof(PCBConf));
  194.  
  195.